#include "std/list.h"
#include "arch/cpu.h"
#include "arch/sys.h"
#include "kernel/proc.h"

thread_t* current_thd;

void __reg2 _switch_to(thread_arch_data_t* prev, thread_arch_data_t* next)
{
	thread_t *p = list_entry(thread_t, arch_data, prev);
	thread_t *n = list_entry(thread_t, arch_data, next);

	// reload cr3 if necessary
	if (p->task->mm.page_dir != n->task->mm.page_dir)
	{
		main_tss.cr3 = (uint)n->task->mm.page_dir;
		__load_cr3(n->task->mm.page_dir);
	}

	// reload esp0(todo)
	main_tss.esp0 = 0;

	// update the current thread
	current_thd = n;
}

/* EOF */
